package ${basePackage}.web.controller;

import ${basePackage}.domain.entities.master.${modelNameUpperCamel};
import ${basePackage}.domain.service.I${modelNameUpperCamel}Service;

import com.hopechart.micro.common.constant.HttpStatus;
import com.hopechart.micro.common.constant.Response;
import com.hopechart.micro.web.controller.admin.BaseController;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
* @author daijiang@hopechart.com
*/
@RestController
@RequestMapping("/${baseRequestMapping}")
public class ${modelNameUpperCamel}Controller extends BaseController {

    @Autowired
    private I${modelNameUpperCamel}Service ${modelNameLowerCamel}Service;

    @RequestMapping(value = "", method = RequestMethod.POST)
    public Response save(${modelNameUpperCamel} ${modelNameLowerCamel}) {
        ${modelNameLowerCamel}Service.save(${modelNameLowerCamel});
        return new Response(HttpStatus.HTTP_STATUS_200);
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public Response delete(@PathVariable("id") Object id) {
	    ${modelNameLowerCamel}Service.deleteByPrimaryKey(id);
        return new Response(HttpStatus.HTTP_STATUS_200);
    }

    @RequestMapping(value = "", method = RequestMethod.PUT)
    public Response update(${modelNameUpperCamel} ${modelNameLowerCamel}) {
	    ${modelNameLowerCamel}Service.updateAll(${modelNameLowerCamel});
        return new Response(HttpStatus.HTTP_STATUS_200);
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public Response detail(@PathVariable("id") Object id) {
        ${modelNameUpperCamel} ${modelNameLowerCamel} = ${modelNameLowerCamel}Service.selectByKey(id);
        return new Response(HttpStatus.HTTP_STATUS_200, ${modelNameLowerCamel});
    }

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Response list(@RequestParam(defaultValue = "1") Integer pageNum,
                        @RequestParam(defaultValue = "20") Integer pageSize,
                        @RequestParam(required = false) ${modelNameUpperCamel} param) {
        PageInfo<${modelNameUpperCamel}> paging = ${modelNameLowerCamel}Service.selectPage(pageNum, pageSize, param);
        return new Response(HttpStatus.HTTP_STATUS_200, parseToRows(paging));
    }
}
